FROM ubuntu:ustc
SHELL ["/bin/bash", "-c"]
ARG U_NAME=jenkins
ARG U_ID=6002

ADD openjdk-21.0.1_linux-x64_bin.tar.gz /opt/env/jdk/
COPY jenkins.war /opt/env/jenkins/
COPY entrypoint.sh /entrypoint.sh

ENV JAVA_HOME=/opt/env/jdk/jdk-21.0.1
ENV JENKINS_HOME=/srv/jenkins
ENV JENKINS_MANAGE_PORT=8080
ENV JENKINS_SLAVE_AGENT_PORT=50000

RUN groupadd ${U_NAME} -g ${U_ID}; \
useradd -u ${U_ID} -g ${U_ID} -d /home/${U_NAME} -m -s /sbin/nologin ${U_NAME}; \
mkdir -p /srv/jenkins/{data,logs}; chown -R ${U_NAME}:${U_NAME} /srv/jenkins; \
apt-get install -y libfreetype6 libfontconfig1 dos2unix; \
apt-get clean ; apt-get autoclean ; apt-get autoremove ; rm -rf /var/lib/apt/lists/* ; \
dos2unix /entrypoint.sh; chmod +x /entrypoint.sh

EXPOSE 8080
EXPOSE 50000

VOLUME /srv/jenkins

USER ${U_NAME}

ENTRYPOINT ["/entrypoint.sh"]